package master

import (
	"github.com/hwcer/cosgo/values"
	"github.com/hwcer/logger"
	"github.com/hwcer/yyds/context"
	"github.com/hwcer/yyds/options"
	"strings"
)

func init() {
	Register(Notify)
}

// Notify 只能发本服玩家
func Notify(c *context.Context) interface{} {
	ids := c.GetMetadata(options.ServiceMetadataUID)
	if ids == "" {
		return values.Error("uid empty")
	}
	req := values.Metadata(c.Metadata())
	data := c.Bytes()
	arr := strings.Split(ids, ",")
	for _, v := range arr {
		if err := Send(v, data, req.Clone()); err != nil {
			logger.Debug("Notify Send error:%v", err)
		}
	}
	return true
}
